$(document).ready(function(){
    $("#button1").click(function(){
        var username = $("#username").val()
        if (username == '') {
            alert('用户名不能为空！');
            return false;
        }
    
        var phone = $("#phone").val()
         if(!(/^1[3456789]\d{9}$/.test(phone))){
           alert("手机号码有误，请重填");
           return false;
        }

        var password = $("#password").val()
            if(password == ''){
            alert('密码不能为空');
            return false;
        }

        var confirm_password = $("#confirm_password").val()
            if(password != confirm_password){
            alert('密码不一致');
            return false;
        }
        
        var sex = $("input[type='radio']:checked").val();

        var now = new Date();
        var create_time = now.getFullYear() + "-" +((now.getMonth()+1)<10?"0":"")+(now.getMonth()+1)+"-"+(now.getDate()<10?"0":"")+now.getDate();

        $.ajax({
                type:"post",
                url:"addManager",
                data:{username:username,phone:phone,password:password,sex:sex,create_time:create_time},
                dataType:"text",   
                success:function (data) {
                if(data=="false") {
                  alert("注册失败！")
                  location.href="register"
                }
                else {
                  //window.sessionStorage.setItem("token", data)
                  alert("注册成功！" + data)
        
                  location.href = "login"
                }
              },
              error:function () {
                alert("严重注册失败！")
            }
        });
      });
    
    })